﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Assist;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.Plumbing
{
	public partial class FormLaySubWaterCatcher : System.Windows.Forms.Form
	{
		public FormLaySubWaterCatcher()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
			this.InitCombBox();
			this.InitParameterSetting();
			this.InitPictureBox();
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			if (this.tbLevel.Text != "")
			{
				this.offset = double.Parse(this.tbLevel.Text.Trim());
				this.isHave = this.checkBox.Checked;
				this.count = int.Parse(this.comboBox.SelectedItem.ToString());
				if (!this.isHave)
				{
					this.id = this.count + 10;
				}
				else
				{
					this.id = this.count;
				}
				this.UserSettingWrite();
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Information("参数不能为空");
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void checkBox_CheckedChanged(object sender, EventArgs e)
		{
			this.InitPictureBox();
		}

		private void InitPictureBox()
		{
			if (this.checkBox.Checked)
			{
				this.pictureBox.Image = new Bitmap(Path.Combine(Product.FamilyImageLocation, "SubWaterCatcher", "带阀件的分集水器.png"));
				return;
			}
			this.pictureBox.Image = new Bitmap(Path.Combine(Product.FamilyImageLocation, "SubWaterCatcher", "不带阀件的分集水器.png"));
		}

		private void InitCombBox()
		{
			if (this.comboBox.Items.Count > 0)
			{
				this.comboBox.Items.Clear();
				return;
			}
			this.comboBox.Items.Add("2");
			this.comboBox.Items.Add("3");
			this.comboBox.Items.Add("4");
			this.comboBox.Items.Add("5");
			this.comboBox.Items.Add("6");
			this.comboBox.Items.Add("7");
		}

		private void InitParameterSetting()
		{
			this.dic = this.userSetting.GetLaySubWaterCatcherSetting();
			this.comboBox.SelectedIndex = int.Parse(this.userSetting.GetValueFromDic("count", "0", this.dic));
			this.checkBox.Checked = Convert.ToBoolean(this.userSetting.GetValueFromDic("isHave", "True", this.dic));
			this.tbLevel.Text = this.userSetting.GetValueFromDic("offset", "0.5", this.dic);
		}

		private void UserSettingWrite()
		{
			this.tbLevel.Text = StringTools.RemoveZero(this.tbLevel.Text.Trim());
			try
			{
				Dictionary<string, string> dictionary = new Dictionary<string, string>();
				dictionary.Add("isHave", this.checkBox.Checked.ToString());
				dictionary.Add("offset", this.tbLevel.Text);
				dictionary.Add("count", this.comboBox.SelectedIndex.ToString());
				this.userSetting.WriteLaySubWaterCatcherSetting(dictionary);
			}
			catch (Exception)
			{
			}
		}

		private HVACUserSetting userSetting = new HVACUserSetting();

		public double offset = 0.5;

		private int count = 6;

		public int id = 6;

		public bool isHave = true;

		private Dictionary<string, string> dic;
	}
}
